﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Prism.ViewModel;

namespace ZSens
{
    public class Player
    {
        // status when just created. by network: ... -> constructing.
        public const int Constructing = 0;
        // status when assigned layout but haven't been sent to remote side. by ui: constructing -> pending
        public const int Pending = 1;
        // status when assigned layout sent to remote side. by network: pending -> running
        public const int Running = 2;
        // status when player is to be removed. by ui: running -> recycling
        public const int Recycling = 3;
        // status when player is to be removed2. by vmulti: recycling -> destructing...
        public const int Destructing = 4;
        // by network destructing -> ....
        public const int Timeout = 5000;

        public int status { get; set; }
        public readonly object lockDisconnect = new object();

        public String playerName { get; private set; }

        public Layout layout { get;  set; }
        public Boolean mapStatus { get; set; }
        public Boolean mapStatusOld { get; set; }

        public Boolean received { get; set; }
        public long lostTime { get; set; }
        public long lastTime { get; set; }

        public Player(String playerName)
        {
            this.playerName = playerName;
            this.layout = null;

            status = Player.Constructing;
            mapStatus = false;
            mapStatusOld = false;
            lostTime = 0;
            lastTime = 0;
            received = false;
        }
        
        public Player(String playerName, Layout layout)
        {
            this.playerName = playerName;
            this.layout = layout;

            status = Player.Constructing;
            mapStatus = false;
            mapStatusOld = false;
            lostTime = 0;
            lastTime = 0;
            received = false;
        }

        public void UpdateAction()
        {
            layout.DoVMultiUpdate();    
        }
    }
}
